package simple

func maxDepth(s string) int {
	stack := make([]byte, 0, len(s))
	result := 0
	for _, ch := range s {
		switch ch {
		case '(':
			stack = append(stack, '(')
		case ')':
			if len(stack) <= 0 {
				continue
			}
			if len(stack) > result {
				result = len(stack)
			}
			stack = stack[:len(stack)-1]
		}
	}
	return result
}
